<template>
  <footer class="footer">
    <span class="todo-count">剩余<strong>{{ modCount }}</strong></span>
    <ul class="filters">
      <li>
        <a :class="{selected: current == '全部'}" @click="doSel('全部')" href="javascript:;">全部</a>
      </li>
      <li>
        <a :class="{selected: current == '未完成'}" @click="doSel('未完成')" href="javascript:;">未完成</a>
      </li>
      <li>
        <a :class="{selected: current == '已完成'}" @click="doSel('已完成')" href="javascript:;">已完成</a>
      </li>
    </ul>
    <button @click="delAllDone" class="clear-completed">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: ['list'],

  data() {
    return {
      current: '全部'
    }
  },
  methods: {
    doSel (sel) {
      // 把sel赋值给current
      this.current = sel
      // 再多加一句话，通知父组件，把sel的值给父组件
      this.$emit('statusChange', sel)
    },

    delAllDone () {
      // 规范写法是通知父组件来删除
      this.$emit('delAllDone')
    }
  },

  computed: {
    // 得到剩余数量
    modCount () {
      let count = 0
      this.list.forEach(v => {
        // 代表找到未完成的，然后再让数量+1
        if (!v.isDone) {
          count++
        }
      })
      return count
    }
  }
};
</script>